package com.xbh.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @program: common-utils
 * @description:
 * @author: 许宝华
 * @create: 2021-09-03 20:16
 */

@Component
public class FieldFillHandler implements MetaObjectHandler {
    private static final Logger log = LoggerFactory.getLogger(FieldFillHandler.class);

    public FieldFillHandler() {
    }

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
